package com.example.apiproject.controller;


import com.example.apiproject.entity.Report;
import com.example.apiproject.service.ReportService;
import com.example.apiproject.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;


@RequestMapping("/report")
@RestController
public class ReportController {
    @Autowired
    private ReportService reportService;

    /**
     * 新增举报反馈
     * @param request
     * @param articleId
     * @param types
     * @param content
     * @return
     */
    @PostMapping("/add")
    public R add(HttpServletRequest request, String articleId, String types, String content){
        return R.ok().put("result",reportService.insert(request,articleId,types,content));
    }

    /**
     * 更新
     * @param report
     * @return
     */
    @PutMapping("/update")
    public R update(@RequestBody Report report){
        return R.ok().put("result",reportService.update(report));
    }

    /**
     * 查询待处理或者已处理的举报
     * @param status
     * @return
     */
    @GetMapping("/{status}")
    public R queryByStatus(@PathVariable Integer status){
        return R.ok().put("result",reportService.queryByStatus(status));
    }

    /**
     * 查询某用户所有举报
     * @param request
     * @return
     */
    @GetMapping("/own")
    public R queryByUserId(HttpServletRequest request){
        return R.ok().put("result",reportService.queryByUserId(request));
    }

    /**
     * 查询全部
     */
    @GetMapping("/all")
    public R queryAll(){
        return R.ok().put("result",reportService.queryAll());

    }
    /**
     * 根据id删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete")
    public R delete(Integer id){
        return R.ok().put("result",reportService.delete(id));
    }

}
